package deviceSyc;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class MQProducer extends MQCon{

    public static void main(String[] args) throws IOException, TimeoutException {
        MQProducer ms = new MQProducer();
    	for(int i=0;i<1000;i++){
    		ms.sendMsg("hello world","110");    		
    	}
    }
    
    public MQProducer() throws IOException{
        super();
    }
    
    public void sendMsg(String msg) throws IOException, TimeoutException{
        //  声明一个队列        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        //发送消息到队列中
        channel.basicPublish(exchangeName, queueName, null, msg.getBytes("UTF-8"));
        System.out.println("Producer Send +'" + msg + "'");
    }
    
    public void sendMsg(String msg,String cityID) throws IOException {
    	//remove the cityCode
//        channel.basicPublish(exchangeName, routingKey+cityID, null, msg.getBytes()); 
        channel.basicPublish(exchangeName, routingKey, null, msg.getBytes("UTF-8")); 
//        System.out.println("Producer Send +'" + msg + "'  --routingKey= "+routingKey+cityID);
        System.out.println("Producer Send +'" + msg + "'  --routingKey= "+routingKey);
    }
}